#ifndef USER_API_TYPES_H
#define USER_API_TYPES_H 1
#pragma once

#include "stm32f10x.h"
#include "board_types.h"


#define PI 3.1415926

typedef struct control_pid_est_t
{
    /* Read "from" write "to" board. */
    /* Horizont. */
    /* Roll dynamic PID. */
    uint16_t PID_Roll_Kp;
    uint16_t PID_Roll_Ki;
    uint16_t PID_Roll_Kd;
    /* Pitch dynamic PID. */
    uint16_t PID_Pitch_Kp;
    uint16_t PID_Pitch_Ki;
    uint16_t PID_Pitch_Kd;
    /* Yaw dynamic PID. */
    uint16_t PID_Yaw_Kp;
    uint16_t PID_Yaw_Ki;
    uint16_t PID_Yaw_Kd;
    /* Used for ordinare PID. */
    uint16_t PID_Level_Kp;
    uint16_t PID_Level_Ki;
    uint16_t PID_Level_Kd;
    /* Relation in Horrizont Kalman filter between Gyro and Accel */
    uint16_t Horizont_Kalman_Coeff;
/* Altitude Baro. */
    /* Used for keep altitude using Baro sensor. */
    uint16_t PID_Altitude_Kp;
    uint16_t PID_Altitude_Ki;
    uint16_t PID_Altitude_Kd;
    /* Used for keep velocity using Baro sensor. */
    uint16_t PID_Velocity_Kp;
    uint16_t PID_Velocity_Ki;
    uint16_t PID_Velocity_Kd;
/* Distance Sonar. */
    /* Used for keep distance using sonar sensor. */
    uint16_t PID_Distance_Kp;
    uint16_t PID_Distance_Ki;
    uint16_t PID_Distance_Kd;
/* Direction. */
    /* Used for keep distance using sonar sensor. */
    uint16_t PID_Direction_Kp;
    uint16_t PID_Direction_Ki;
    uint16_t PID_Direction_Kd;
    /* Relation in Direction Kalman filter between Gyro and Magnetometer */
    uint16_t Direction_Kalman_Coeff;
/* PPM zero shift. */
    uint16_t PPM_shift_ch1;
    uint16_t PPM_shift_ch2;
    uint16_t PPM_shift_ch3;
    uint16_t PPM_shift_ch4;
    uint16_t PPM_shift_ch5;
    uint16_t PPM_shift_ch6;

    /* Read only from board. */
/* Acceleration. */
    int16_t Acceleration_raw_X;
    int16_t Acceleration_raw_Y;
    int16_t Acceleration_raw_Z;
    int16_t Acceleration_Filtered_X;
    int16_t Acceleration_Filtered_Y;
    int16_t Acceleration_Filtered_Z;
/* Gyro. */
    int16_t Gyro_raw_XY;// Z axis
    int16_t Gyro_raw_YZ;// X axis
    int16_t Gyro_raw_XZ;// Y axis
    int16_t Gyro_Filtered_XY;// Z axis
    int16_t Gyro_Filtered_YZ;// X axis
    int16_t Gyro_Filtered_XZ;// Y axis
/* Magnetometer. */
    int16_t Magnetometer_raw_X;
    int16_t Magnetometer_raw_Y;
    int16_t Magnetometer_raw_Z;
    int16_t Magnetometer_Filtered_X;
    int16_t Magnetometer_Filtered_Y;
    int16_t Magnetometer_Filtered_Z;
/* Barometer. */
    int16_t Barometer_Altitude_raw;
    int16_t Barometer_Altitude_Filtered;
    int16_t Barometer_Velocity_raw;
    int16_t Barometer_Velocity_Filtered;
    int16_t Barometer_Temperature;
/* Sonar */
    int16_t Sonar_Distance;  //56

/* Main Rotor rotation speed */
    int32_t Main_Rotor_Rotation_Speed;

/* PWM output. */
    uint16_t Motor_Servo_1;
    uint16_t Motor_Servo_2;
    uint16_t Motor_Servo_3;
    uint16_t Motor_Servo_4;
    uint16_t Motor_Servo_5;
    uint16_t Motor_Servo_6;

/* System data. */
    uint32_t BoardSystemTime;
    uint32_t Temp_u32;
    int32_t  Temp_i32;
/* Control summ. */
    uint16_t CRC_summ;

} control_pid_est_t;




/*
* This structure using for saving PIDs parameters to FLASH and reading it back.
* Main idea is use it like pointer in board sensor_raw_data_t structure.
* So we will have structure of pointers that allow as make management more easy.
*/
typedef struct sensor_PID_data_t
{
    /* Read "from" write "to" board. */

    /* Pitch PID. */
    uint16_t Pitch_kP_pid;
    uint16_t Pitch_kP_pid_dynamic;
    uint16_t Pitch_kI_pid;
    uint16_t Pitch_kI_pid_dynamic;
    uint16_t Pitch_kD_pid;
    uint16_t Pitch_kD_pid_dynamic;

    /* Roll  PID. */
    uint16_t Roll_kP_pid;
    uint16_t Roll_kP_pid_dynamic;
    uint16_t Roll_kI_pid;
    uint16_t Roll_kI_pid_dynamic;
    uint16_t Roll_kD_pid;
    uint16_t Roll_kD_pid_dynamic;

    /* Yaw dynamic PID. */
    uint16_t Yaw_kP_pid;
    uint16_t Yaw_kP_pid_dynamic;
    uint16_t Yaw_kI_pid;
    uint16_t Yaw_kI_pid_dynamic;
    uint16_t Yaw_kD_pid;
    uint16_t Yaw_kD_pid_dynamic;
} sensor_PID_data_t;


typedef struct sensor_raw_data_t
{
    /* Read only from board. */
/* Acceleration. */
    int16_t Acceleration_raw_X;
    int16_t Acceleration_raw_Y;
    int16_t Acceleration_raw_Z;
/* Gyro. */
    int16_t Gyro_raw_XY;// Z axis
    int16_t Gyro_raw_YZ;// X axis
    int16_t Gyro_raw_XZ;// Y axis
/* Magnetometer. */
    int16_t Magnetometer_raw_X;
    int16_t Magnetometer_raw_Y;
    int16_t Magnetometer_raw_Z;
/* Quaternion */
    floatAndUint32_t  Quaternion[4];
/* Euler_Angles */
    floatAndUint32_t  Euler_Angle[3];
/* System data. */
    uint32_t BoardSystemTime;
/* Pointer to sensor PID data */
    sensor_PID_data_t *PID;
/* Control summ. */
    uint16_t CRC_summ;

} sensor_raw_data_t;


typedef struct sensor_float_data_t
{
    /* Read only from board. */
/* Acceleration. */
    float Acceleration_X;
    float Acceleration_Y;
    float Acceleration_Z;
/* Gyro. */
    float Gyro_X;
    float Gyro_Y;
    float Gyro_Z;
/* Magnetometer. */
    float Magnetometer_X;
    float Magnetometer_Y;
    float Magnetometer_Z;
} sensor_float_data_t;

typedef struct float_3D_data_t
{
    float X;
    float Y;
    float Z;
} float_3D_data_t;

typedef struct euler_angle_t
{
    float phi;
    float theta;
    float psi;
} euler_angle_t;

















#endif